<?php
	class Transaction extends AppModel
	{
		var $name = "Transaction";
		const SUCCESSFUL = 1;
		const FAILED =2;
		var $belongsTo = array(
			'Order'=> array('className'=>"PaidListings.Order",'counterScope'=> true),
		);
		var $fieldProperties = array(
			'information' => array('fieldModifier'=>'toggleSerialized'),
		);
		function createTransaction(AbstractPaymentHandler $PaymentHandler,$order,$status = self::SUCCESSFUL,$information = array())
		{
			$data = array("order_id"=>$order['Order']['id'],
				'amount' => $order['Order']['total_amount'],
				'status' => $status,
				'payment_handler'=> $PaymentHandler->name,	
				'information' => $information,
			);
			$this->create();
			$this->save(array($this->alias => $data));
			$id = $this->id;
			if($status == self::SUCCESSFUL)
			{
				$this->recursive = -1;
				$transaction = $this->findById($this->id);
				PaidListingNotification::getInstance()->orderProcessed($order,$transaction);
			}
			return $id;
		}
	}
?>